package top.laoshuzi.scad.mosinnagant.model

import eu.printingin3d.javascad.coords.Coords3d
import eu.printingin3d.javascad.models.Polyhedron
import top.laoshuzi.scad.mosinnagant.utils.ScadUtils

/**
 * Created by mouse on 2019/7/21.
 */
object ExtPolyhedron {

    fun side4Cubeoid(length: Double, bottomSize: Double, topSize: Double): Polyhedron {
        return side4Cubeoid(length, bottomSize, bottomSize, topSize, topSize)
    }

    fun side4Cubeoid(
        length: Double,
        bottomLong: Double,
        bottomWide: Double,
        topLong: Double,
        topWide: Double
    ): Polyhedron {

        val bl = bottomLong / 2
        val bw = bottomWide / 2
        val tl = topLong / 2
        val tw = topWide / 2
        val l = length / 2

        return ScadUtils.polyhedron(
            arrayListOf(
                Coords3d(-bl, -bw, -l),
                Coords3d(bl, -bw, -l),
                Coords3d(bl, bw, -l),
                Coords3d(-bl, bw, -l),
                Coords3d(-tl, -tw, l),
                Coords3d(tl, -tw, l),
                Coords3d(tl, tw, l),
                Coords3d(-tl, tw, l)
            ),
            arrayOf(
                arrayOf(0, 1, 2, 3),
                arrayOf(4, 5, 1, 0),
                arrayOf(7, 4, 0, 3),
                arrayOf(6, 7, 3, 2),
                arrayOf(5, 6, 2, 1),
                arrayOf(7, 6, 5, 4)
            )
        )
    }

    fun side3Cubeoid(
        length: Double,
        bottomLong: Double,
        bottomWide: Double,
        bottomVertexX: Double,
        topLong: Double,
        topWide: Double,
        topVertexX: Double
    ): Polyhedron {

        val bl = bottomLong / 2
        val bw = bottomWide / 2
        val tl = topLong / 2
        val tw = topWide / 2
        val l = length / 2

        return side3Cubeoid(
            Coords3d(-bl, -bw, -l),
            Coords3d(bl, -bw, -l),
            Coords3d(bottomVertexX - bl, bw, -l),
            Coords3d(-bl, -bw, l),
            Coords3d(bl, -bw, l),
            Coords3d(topVertexX - bl, bw, l)
        )
    }

    fun side3Cubeoid(
        c0: Coords3d,
        c1: Coords3d,
        c2: Coords3d,
        c3: Coords3d,
        c4: Coords3d,
        c5: Coords3d
    ): Polyhedron {
        return ScadUtils.polyhedron(
            arrayListOf(
                c0,
                c1,
                c2,
                c3,
                c4,
                c5
            ),
            arrayOf(
                arrayOf(0, 1, 2),
                arrayOf(3, 4, 1, 0),
                arrayOf(5, 3, 0, 2),
                arrayOf(4, 5, 2, 1),
                arrayOf(3, 5, 4)
            )
        )
    }

}
